{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "разбор ДЗ 2.ipynb",
      "provenance": []
    },
    "kernelspec": {
      "display_name": "Python 3 (ipykernel)",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.8.12"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Ykn9g3xPSVsM"
      },
      "source": [
        "# Линейное пространство. Основные понятия. Часть 2"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "CUanUo8XSVsk"
      },
      "source": [
        "# Домашнее задание"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "6qRNDHdsSVsn"
      },
      "source": [
        "__1.__ Найти скалярное произведение векторов $x, y \\in \\mathbb{R}$:\n",
        "\n",
        "а) $x=(0,-3, 6),~y=(-4, 7, 9);$\n",
        "\n",
        "б) $x=(7, -4, 0, 1),~y=(-3, 1, 11, 2).$"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "NAJsLuuLSVsn"
      },
      "source": [
        "__Решение__"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "xl13Ot_mSVso"
      },
      "source": [
        "import numpy as np\n",
        "from numpy.linalg import norm\n",
        "import matplotlib.pyplot as plt"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "1ssfE6W5SVsp"
      },
      "source": [
        "x = np.array([0, -3, 6])\n",
        "y = np.array([-4, 7, 9])"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "8yS3_DhMSVsq",
        "outputId": "fbac8272-d82e-4152-f8be-75685b035def"
      },
      "source": [
        "print(f'(x, y)=\\t{x.dot(y)}')"
      ],
      "execution_count": null,
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "(x, y)=\t33\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "_TMM-bBfSVsv"
      },
      "source": [
        "x = np.array([7, -4, 0, 1])\n",
        "y = np.array([-3, 1, 11, 2])"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "J5GrPDjRSVsy",
        "outputId": "f807caf5-4ac9-4385-b154-91f960bf6a02"
      },
      "source": [
        "print(f'(x, y)=\\t{x.dot(y)}')"
      ],
      "execution_count": null,
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "(x, y)=\t-23\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "HoZT9OGtSVsz"
      },
      "source": [
        "__2.__ Найти нормы векторов $(4, 2, 4)$ и $(12, 3, 4)$ и угол между ними."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "cG5T_iYtSVs0"
      },
      "source": [
        "__Решение__"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "25g15977SVs1"
      },
      "source": [
        "a = np.array([4, 2, 4])\n",
        "b = np.array([12, 3, 4])"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "iu5AsvgBSVs3",
        "outputId": "45ca15ac-f6ed-46f7-dd48-d6772077c9fb"
      },
      "source": [
        "print(f'l1 норма вектора a:\\t{norm(a, ord=1)}')\n",
        "print(f'l1 норма вектора b:\\t{norm(b, ord=1)}')"
      ],
      "execution_count": null,
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "l1 норма вектора a:\t10.0\n",
            "l1 норма вектора b:\t19.0\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "VQ1DLNp5SVs5",
        "outputId": "50506722-9f1f-44b7-df70-6b1a0aaa2e5d"
      },
      "source": [
        "print(f'l2 норма вектора a:\\t{norm(a, ord=2)}')\n",
        "print(f'l2 норма вектора b:\\t{norm(b, ord=2)}')"
      ],
      "execution_count": null,
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "l2 норма вектора a:\t6.0\n",
            "l2 норма вектора b:\t13.0\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Nh1Kn9KMSVs6",
        "scrolled": true,
        "outputId": "3c2b2927-3902-4f9b-c678-0ea10b695829"
      },
      "source": [
        "cos_phi = np.dot(a, b) / norm(a) / norm(b)\n",
        "print(f'Косинус угла между a и b: {cos_phi:.2f}')\n",
        "print(f'Угол между a и b: {np.arccos(cos_phi):.2f}')"
      ],
      "execution_count": null,
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "Косинус угла между a и b: 0.90\n",
            "Угол между a и b: 0.46\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "mLgaE4y3SVs7"
      },
      "source": [
        "__3.__ Будет ли линейное пространство евклидовым, если за скалярное произведение принять:<br>\n",
        "а) произведение длин векторов;<br>\n",
        "б) утроенное обычное скалярное произведение векторов?"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "_4jXorBkSVtA"
      },
      "source": [
        "__Решение__"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "TFgIao8jSVtA"
      },
      "source": [
        "а) Нет, так как не выполнится третья аксиома для Евклидова пространства: $(x_{1}+x_{2},y)=(x_{1},y)+(x_{2},y)$<br>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "0Mt7jpw0SVtB"
      },
      "source": [
        "Она выполнится, только если $x_{1} \\mbox{ и } x_{2}$ будут коллинеарны. Если же они не коллинеарны, то норма от $x_{1} + x_{2}$ будет меньше, чем нормы от этих векторов по отдельности."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "IqjTuooQSVtC"
      },
      "source": [
        "б) Да, так как выполнятся все аксиомы для Евклидова пространства"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "ql9dws0gSVtC"
      },
      "source": [
        "__4.__ Какие из нижеперечисленных векторов образуют ортонормированный базис в линейном пространстве $\\mathbb{R}^{3}$:<br>\n",
        "а) $(1,0,0),(0,0,1);$ <br>\n",
        "б) $(1/\\sqrt{2},-1/\\sqrt{2},0),(1/\\sqrt{2},1/\\sqrt{2},0), (0,0,1);$<br>\n",
        "в) $(1/2, -1/2, 0), (0, 1/2, 1/2), (0,0,1);$<br>\n",
        "г) $(1,0,0),(0,1,0),(0,0,1)?$ "
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "IAKYpJVISVtD"
      },
      "source": [
        "__Решение__"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "mq1Oksp0SVtE"
      },
      "source": [
        "а) Образуют ортонормированный базис в $\\mathbb{R}^{3}$, но не являются базисом $\\mathbb{R}^{3}$"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "xR1aux3hSVtE"
      },
      "source": [
        "б) Образуют ортонормированный базис, так как выполняются условия $(e_{i}, e_{j})=0$ $\\forall$ $i\\neq j$ и $(e_{i},e_{i})=1$ $\\forall$ $i\\in[1, n].$"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "DcmJUNWBSVtF"
      },
      "source": [
        "a = np.array([1/(2)**0.5, -1/(2)**0.5, 0])\n",
        "b = np.array([1/(2)**0.5, 1/(2)**0.5, 0])\n",
        "c = np.array([0, 0, 1])"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "JInE5aroSVtG",
        "outputId": "48d1bb28-04ec-4170-965f-3330d5cc77c9"
      },
      "source": [
        "print(f'(a, a)= {a.dot(a):1.0f}')\n",
        "print(f'(b, b)= {b.dot(b):1.0f}')\n",
        "print(f'(c, c)= {c.dot(c):1.0f}')"
      ],
      "execution_count": null,
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "(a, a)= 1\n",
            "(b, b)= 1\n",
            "(c, c)= 1\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "f2HBSeDxSVtH",
        "outputId": "5c3a3c1e-8d29-4e41-c4fa-3da2cac30837"
      },
      "source": [
        "print(f'(a, b)= {a.dot(b)}')\n",
        "print(f'(a, c)= {a.dot(c)}')\n",
        "print(f'(c, b)= {c.dot(b)}')"
      ],
      "execution_count": null,
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "(a, b)= 0.0\n",
            "(a, c)= 0.0\n",
            "(c, b)= 0.0\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "dumRCCL4SVtI"
      },
      "source": [
        "в) Не образуют ортонормированный базис, так как не выполняются условия $(e_{i}, e_{j})=0$ $\\forall$ $i\\neq j$ и $(e_{i},e_{i})=1$ $\\forall$ $i\\in[1, n].$"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "OzGWCy0JSVtI"
      },
      "source": [
        "a = np.array([1/2, -1/2, 0])\n",
        "b = np.array([0, 1/2, 1/2])\n",
        "c = np.array([0, 0, 1])"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "EU2wU1s2SVtJ",
        "outputId": "fbd33b95-5a9c-4063-8356-8ef19da459bf"
      },
      "source": [
        "print(f'(a, a)= {a.dot(a)}')\n",
        "print(f'(b, b)= {b.dot(b)}')\n",
        "print(f'(c, c)= {c.dot(c)}')"
      ],
      "execution_count": null,
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "(a, a)= 0.5\n",
            "(b, b)= 0.5\n",
            "(c, c)= 1\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "YWIx0o8cSVtK",
        "outputId": "42884ce4-9fb1-4ae8-fb09-73c797d4108e"
      },
      "source": [
        "print(f'(a, b)= {a.dot(b)}')\n",
        "print(f'(a, c)= {a.dot(c)}')\n",
        "print(f'(c, b)= {c.dot(b)}')"
      ],
      "execution_count": null,
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "(a, b)= -0.25\n",
            "(a, c)= 0.0\n",
            "(c, b)= 0.5\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "-7Flu_vZSVtK"
      },
      "source": [
        "г) Образуют ортонормированный базис, так как выполняются условия $(e_{i}, e_{j})=0$ $\\forall$ $i\\neq j$ и $(e_{i},e_{i})=1$ $\\forall$ $i\\in[1, n].$"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "MMrrzMHeSVtL"
      },
      "source": [
        "a = np.array([1, 0, 0])\n",
        "b = np.array([0, 1, 0])\n",
        "c = np.array([0, 0, 1])"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "64EkNHAGSVtL",
        "outputId": "d6aa906c-da66-4634-cf6d-c5f901551e2b"
      },
      "source": [
        "print(f'(a, a)= {a.dot(a)}')\n",
        "print(f'(b, b)= {b.dot(b)}')\n",
        "print(f'(c, c)= {c.dot(c)}')"
      ],
      "execution_count": null,
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "(a, a)= 1\n",
            "(b, b)= 1\n",
            "(c, c)= 1\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "33YBONiUSVtN",
        "outputId": "813bec5c-fa1e-4e9c-8993-f05a3062678a"
      },
      "source": [
        "print(f'(a, b)= {a.dot(b)}')\n",
        "print(f'(a, c)= {a.dot(c)}')\n",
        "print(f'(c, b)= {c.dot(b)}')"
      ],
      "execution_count": null,
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "(a, b)= 0\n",
            "(a, c)= 0\n",
            "(c, b)= 0\n"
          ]
        }
      ]
    }
  ]
}